﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using ICeFramework.DataAccess.Enums;
using System.Configuration;
using ICeFramework.Common.DataLayer.Enums;

namespace ICeFramework.DataAccess.SqlConnections
{
    public class Utils
    {
        

        public string GetConnectionString(ServerType serverType, string server, string database, string userName, string password, int port)
        {
            string connStr = string.Empty;
            bool trustedConnection = string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password);
            if (serverType == ServerType.MsSql)
            {
                connStr += string.Format("Server={0};", server);
                if (!string.IsNullOrEmpty(database))
                {
                    connStr += string.Format("Database={0};", database);
                }

                if (trustedConnection)
                {
                    connStr += "Trusted_Connection=True;";
                }
                else
                {
                    connStr += string.Format("User ID={0};", userName);
                    connStr += string.Format("Password={0};", password);
                }
            }
            else
            {
                connStr += string.Format("Server={0};", server);
                if (!string.IsNullOrEmpty(database))
                {
                    connStr += string.Format("Database={0};", database);
                }
                connStr += string.Format("User ID={0};", userName);
                connStr += string.Format("Password={0};", password);
                if (port == 0)
                {
                    connStr += "Port=3306";
                }
                else
                {
                    connStr += string.Format("Port={0}", port);
                }
            }
            return connStr;
        }

    }
}
